import { uploadFile } from "@/utils/upload";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/upload";

export const upload_up = (
  filePath: string,
  formData: any,
  showError = true
) => {
  return uploadFile<{ url: string; save_name: string }[]>(
    `${baseUrl}/upload`,
    filePath,
    formData
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const mini_upload_up = (
  filePath: string,
  formData: any,
  showError = true
) => {
  return uploadFile<{ url: string; save_name: string }[]>(
    `${baseUrl}/mini_upload`,
    filePath,
    formData
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const upload_up2 = (
  filePath: string,
  formData: any,
  showError = true
) => {
  return uploadFile<{ url: string; save_name: string }[]>(
    `${baseUrl}/big_file_upload`,
    filePath,
    formData
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};
